// vite.config.js
import vue from '@vitejs/plugin-vue'
// import AutoImport from 'unplugin-auto-import/vite'
// import Components from 'unplugin-vue-components/vite'
// import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { loadEnv, defineConfig } from "vite";
// import viteSvgIcons from 'vite-plugin-svg-icons'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'

import path from 'path'


export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());

  return {
    plugins: [
      vue(),
 
      createSvgIconsPlugin({
        // 指定 SVG 图标存放目录（需提前创建，存放所有自定义 SVG）
        iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
        // 指定 symbolId 格式（默认即可，用于引用）
        symbolId: 'icon-[dir]-[name]'
      })
    ],
    css: {
      preprocessorOptions: {
        scss: {
          // 全局变量
          // additionalData: '@import "./src/assets/style/global-variables.scss";',
          // element-plus升级到v2需要改成以下写法
          additionalData: `@use "./src/assets/style/global-variables.scss" as *;`,
        },
      },
    },
    base: './',
    resolve: {
      alias: {
        '@': '/src',
      },
    },
    build: {
      outDir: 'EdaPlus',
      emptyOutDir: true,
    },
    server: {
      port: 5000,
      host: '0.0.0.0',
      open: true,
      proxy: {
        ['/testapi']: {
          // target: 'http://192.168.1.19:10899',
          target: 'http://localhost:10899',
          changeOrigin: true,
          rewrite: (path) => {
            
            return path.replace(new RegExp("^" + '/testapi'), '')
          },
        }
      },
    },
  }
})
